import csv
from openpyxl import load_workbook
import os
folder_path = 'd:/ymx/'
folder_path1 = 'd:/data/'
for root, dirs, files in os.walk(folder_path):
    for file in files:
        file_path = os.path.join(root, file)
for root1, dirs1, files1 in os.walk(folder_path1):
    for file1 in files1:
        file_path1 = os.path.join(root1, file1)
print(file_path1)
data = {}
try:
    with open(file_path1, 'r', encoding="utf-16") as f:
        reader = csv.reader(f, delimiter='\t')
        for row in reader:
            if row[0] in [":BEGIN", ":END"]:
                continue
            key, value = row[0], row[1]
            if key not in data:
                data[key] = []
            data[key].append(value)
except FileNotFoundError:
    print("CSV文件未找到，请检查路径。")
except Exception as e:
    print(f"读取CSV文件时出错：{e}")
output = [f"{key},{','.join(values)}" for key, values in data.items()]
data_array = [line.split(",") for line in output]
wb = load_workbook(file_path)
ws1 = wb[wb.sheetnames[0]]
ws2 = wb[wb.sheetnames[1]]
rows = ws1.max_row
rows += 1  # 直接更新rows变量，不需要新的ROWS变量
for i in range(20, rows):
    print(ws1.cell(i,2).value)
    for row_data in data_array:
        if ws1.cell(i, 2).value == row_data[0]:
            for j in range(1, len(row_data)):
                jj = j + 12
                ws2.cell(i, jj).value = float(row_data[j])
            break
wb.save(file_path)